package com.caojing.haolemai.ui.outlets;

import android.os.Handler;
import android.os.Looper;

import com.caojing.haolemai.bean.tabBean;
import com.caojing.haolemai.bean.TabResultsEntity;

import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/10/17 0017.
 */
public class OutletsPresenter implements OutletsContract.Presenter{
    private OutletsContract.View view;
    private OutletsContract.Modle modle;

public OutletsPresenter(OutletsContract.View view){
    this.view=view;
    this.modle=new OutletsModle();
}

    @Override
    public void getVertical(Map<String, String> params) {
        modle.getVertical(params, new Callback<tabBean>() {
            @Override
            public void onResponse(Call<tabBean> call, Response<tabBean> response) {
                tabBean tabBean=response.body();
                final List<TabResultsEntity> results = tabBean.getResults();
                Handler handler=new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetVerticalSucess(results);
                    }
                });
            }

            @Override
            public void onFailure(Call<tabBean> call, Throwable t) {
                  Handler handler=new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetVerticalFail("网络连接失败");
                    }
                });
            }
        });

    }
}
